package com.haolijun.eecms.controller;

import cn.hutool.json.JSONUtil;
import com.haolijun.eecms.common.R;
import com.haolijun.eecms.controller.form.InsertRepairsForm;
import com.haolijun.eecms.controller.form.SearchRepairsByPageForm;
import com.haolijun.eecms.entity.TbRepairs;
import com.haolijun.eecms.service.FacilityService;
import com.haolijun.eecms.service.RepairsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;

/**
 * @ClassName RepairsController
 * @Description TODO
 * @Author hljstart
 * @Date 2023/3/12 16:53
 * @Version 1.0
 */
@RestController
@RequestMapping("/repairs")
@Tag(name = "RepairsController",description = "报修Web接口")
public class RepairsController {

    @Autowired
    private RepairsService repairsService;


    @PostMapping("/searchRepairByPage")
    @Operation(summary = "查询报修分页数据")
    public R searchRepairByPage(@Valid @RequestBody SearchRepairsByPageForm form){
        HashMap param = JSONUtil.parse(form).toBean(HashMap.class);
        R r = repairsService.searchRepairsByPage(param);
        return r;
    }

    @GetMapping("/searchRepairInfo/{id}")
    @Operation(summary = "查询报修数据详情")
    public R searchRepairInfo(@PathVariable("id") Integer id){
        HashMap param = repairsService.searchRepairsInfo(id);
        return R.ok().data(param);
    }

    @PostMapping("/insert")
    @Operation(summary = "报修" )
    public R insert(@Valid @RequestBody InsertRepairsForm form){
        TbRepairs repairs = JSONUtil.parse(form).toBean(TbRepairs.class);
        R r = repairsService.insert(repairs);
        return r;
    }

    @GetMapping("/repairsAccomplish/{id}")
    @Operation(summary = "维修完成" )
    public R repairsAccomplish(@PathVariable("id") Integer id){
        R r = repairsService.repairsAccomplish(id);
        return r;
    }


    @GetMapping("/breakage/{id}")
    @Operation(summary = "设备报损" )
    public R breakage(@PathVariable("id") Integer id){
        R r = repairsService.breakage(id);
        return r;
    }
}
